package previous.Test_0209;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
public class Solution {
    //找出所有子集的异或在求和
    //总和
    int ret;
    //每个异或总和
    int path;
    public int subsetXORSum(int[] nums) {
         dfs(nums,0);
         return ret;
    }
    public void dfs(int[] nums,int pos){
        ret+=path;
        //先求出子集
        for (int i = pos; i < nums.length; i++) {
            //选
            path^=nums[i];
            //不选
            dfs(nums,i+1);
            //回溯
            path^=nums[i];
        }
    }

}
